package com.website.view.component
{
	import com.greensock.*;
	import com.website.util.Constant;
	
	import flash.display.*;
	import flash.events.MouseEvent;
	import flash.text.*;
	
	public class ClickBtnComp extends Sprite
	{
		public var field:TextField;
		public var bg:Sprite;
		public var btn:Sprite;
		protected var _rollOverColor:String;
		
		public function ClickBtnComp(text:String,rollOverColor:String,size:int = 14, fontName:String = "") : void
		{
			_rollOverColor = rollOverColor
			field = new TextField();
			var textFormat:TextFormat = new TextFormat();
			bg = new Sprite();
			btn = new Sprite();
			bg.useHandCursor = true;
			bg.mouseEnabled = true;
			bg.buttonMode = true;
			bg.graphics.beginFill(10066329, 0);
			bg.graphics.drawRect(0, 0, 1, 1);
			bg.graphics.endFill();
			addChild(bg);
			if(fontName != "")
			{
//	            textFormat.font = fontName;
//				field.embedFonts = true;
			}
			textFormat.size = 14;
			textFormat.letterSpacing = 0;
			textFormat.leftMargin = 0;
			textFormat.rightMargin = 0;
			textFormat.color = Constant.coldColor;
			btn.useHandCursor = true;
			btn.mouseEnabled = true;
			btn.buttonMode = true;
			btn.mouseChildren = false;
			field.autoSize = "left";
			field.antiAliasType = AntiAliasType.ADVANCED;
			field.gridFitType = GridFitType.PIXEL;
			field.defaultTextFormat = textFormat;
			field.text = text;
			btn.addChild(field);
			addChild(btn);
			addEventListener(MouseEvent.ROLL_OVER, rollOver);
			addEventListener(MouseEvent.ROLL_OUT, rollOut);
			
		}
		
		protected function rollOut(event:MouseEvent) : void
		{
			TweenMax.to(field, Constant.fadeSpeed, {tint:Constant.coldColor, alpha:1, overwrite:true});
		}
		
		protected function rollOver(event:MouseEvent) : void
		{
			TweenMax.to(field, Constant.fadeSpeed, {tint:_rollOverColor, alpha:1, overwrite:true});
		}
		
	}
}
